/**
 * Ingenius-Group S.A.S
 *
 * Project: SAU
 * File: Feature.java
 * Date: 17/11/2010
 */

package com.ingenius.sau.shared.model.guidelines;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.FetchGroup;
import javax.jdo.annotations.FetchGroups;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NullValue;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.ingenius.sau.shared.model.core.BaseBean;

/**
 * Class <strong>Feature</strong>
 * 
 * @author Jesus David
 * @version 0.1
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
@FetchGroups({
		@FetchGroup(name = "with_factor", members = { @Persistent(name = "factor") }),
		@FetchGroup(name = "with_indicators", members = { @Persistent(name = "indicators") }) })
public class Feature implements BaseBean {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String id;

	@Persistent(nullValue = NullValue.NONE)
	private String name;

	@Persistent(nullValue = NullValue.NONE)
	private String description;

	@Persistent(nullValue = NullValue.NONE)
	private String aspects2Evaluate;

	@Persistent
	private Factor factor;

	@Persistent(mappedBy = "feature")
	@Element(dependent = "true")
	private List<Indicator> indicators;

	// CONSTRUCTORS

	public Feature() {
	}

	public Feature(String id) {
		this.id = id;
	}

	// METHODS

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getAspects2Evaluate() {
		return aspects2Evaluate;
	}

	public void setAspects2Evaluate(String aspects2Evaluate) {
		this.aspects2Evaluate = aspects2Evaluate;
	}

	public Factor getFactor() {
		return factor;
	}

	public void setFactor(Factor factor) {
		this.factor = factor;
	}

	public List<Indicator> getIndicators() {
		return (indicators == null) ? indicators = new ArrayList<Indicator>()
				: indicators;
	}

	public void setIndicators(List<Indicator> indicators) {
		this.indicators = indicators;
	}

	public void addIndicator(Indicator indicator) {
		getIndicators().add(indicator);
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Feature) {
			return ((Feature) obj).getId().equals(id);
		}
		return false;
	}

	public Feature toDTO() {
		if (this != null) {
			this.setFactor(null);
			this.setIndicators(null);
		}
		return this;
	}
}
